package structs

import (
	"github.com/fatih/color"
	"pingce/core/helper"
	"pingce/sdk/soe"
)

// SpeakingListener 实现SpeakingAssessmentListener接口
type SpeakingListener struct {
	ID      int
	Key     string
	Channel chan string
}

// OnRecognitionStart 实现SpeakingAssessmentListener接口
func (listener *SpeakingListener) OnRecognitionStart(response *soe.SpeakingAssessmentResponse) {
	// fmt.Println(helper.ToJson(response))
	color.Red("开始响应：%v", helper.ToJson(response))
}

// OnIntermediateResults 实现SpeakingAssessmentListener接口
func (listener *SpeakingListener) OnIntermediateResults(response *soe.SpeakingAssessmentResponse) {
	color.Red("Intermediate响应：%v", helper.ToJson(response))
	listener.Channel <- helper.ToJson(response)
}

// OnRecognitionComplete 实现SpeakingAssessmentListener接口
func (listener *SpeakingListener) OnRecognitionComplete(response *soe.SpeakingAssessmentResponse) {
	color.Red("Recognition结果响应：%v", helper.ToJson(response))
	listener.Channel <- helper.ToJson(response)
}

// OnFail implementation of SpeakingAssessmentListener
func (listener *SpeakingListener) OnFail(response *soe.SpeakingAssessmentResponse, err error) {
	color.Red("错误响应：%v", helper.ToJson(response))
}
